package com.tengju.data.infrastructure.repository.clickhouse.user;

import com.tengju.data.domain.model.clickhouse.DwdStarChangeRecordAllRepository;
import com.tengju.data.domain.model.clickhouse.star.DwdStarChangeRecord;
import com.tengju.data.domain.model.user.UserIdCode;
import com.tengju.data.domain.shared.IdObject;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.DwdStarChangeRecordDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.clickhouse.user.DwdStarChangeRecordAllMapper;
import com.tengju.data.infrastructure.repository.clickhouse.convert.DwdStarChangeRecordAllConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class DwdStarChangeRecordAllRepositoryImpl implements DwdStarChangeRecordAllRepository {

    @Resource
    private DwdStarChangeRecordAllMapper dwdStarChangeRecordAllMapper;

    @Override
    public List<DwdStarChangeRecord> getLastRecord(List<UserIdCode> idCodes) {
        List<Long> idCodesVal = idCodes.stream().map(IdObject::getValue).collect(Collectors.toList());
        List<DwdStarChangeRecordDO> lastRecord = dwdStarChangeRecordAllMapper.getLastRecord(idCodesVal);
        return DwdStarChangeRecordAllConvert.toModel(lastRecord);
    }
}
